AS = as
LD = ld -N
CC = gcc -O2 -Wall

BIN = coderunner shell2c booltest
SHELLCODE = $(patsubst %.asm,%, $(wildcard shellcode/*.asm))

ifdef SAFE
DEFS = --defsym SAFE=1
endif

%.o: %.asm Makefile
	$(AS) $(DEFS) $< -o $@

%: %.o
	$(LD) $< -o $@ --oformat=binary

all: $(BIN) shellcode live

live:
	make -C live

shellcode: $(SHELLCODE)

shell2c: shell2c.c
	$(CC) $@.c -o $@

booltest: booltest.c
	$(CC) $@.c -o $@

coderunner: coderunner.asm
	$(AS) $< -o $@.o
	$(LD) $@.o -o $@

clean:
	rm -f $(BIN) $(SHELLCODE) shellcode.h coderunner.o
	make -C live clean

.PHONY: live clean
